import {
    getEmpRecordDetail,
    getEmpRecordHandle,
    getEnvRecordHandle,
    getEnvRecordDetails,
    getFimResultDetail,
    getFimResultHandle,
    getFseRecordHandle,
    getFseRecordDetails,
} from "@/api/api.js";
import {
    getMachRecordHandle_V1,
    getMachRecordDetail_V1
} from "@/api/mach.js";
import {
    getEquipRecordDetail,
    getEquipRecordHandle
} from "@/api/equip.js";
import {
    problemReportDetails,
    problemReportLog
} from "@/api/quality.js";
import {
    safetyProblemReportDetails,
    safetyProblemReportLog
} from "@/api/safety.js"

export const RecordCreate = {
    data() {
        return {
            // 报警详情信息
            modelName: "",
            code: "",
            ruleMinValue: "",
            handleRemark: "",
            handleResult: "",
            handleTime: "",
            handleUserName: "",
            machTypeName: "",
            machBrandName: "",
            machModelName: "",
            machCode: "",
            empName: "",
            workTypeName: "",
            operatorList: [],
            ruleType: "",
            ruleMaxValue: "",
            type: "",
            pointList: [],
            centerPoint: [],
            radius: "",
            timeList: [],
            triggerTime: "",
            triggerValue: "",
            ads: "",
            warnId: "",
            moduleType: 0,
            deviceType: "",
            envName: "",
            deviceName: "",
            personNameList: "",
            algCheckType: "",
            algCheckTypeName: "",
            imgList: [],
            // ruleMinValue:"",
            pageNumIndex: 1,
            problemReport: {},
            reportImgUrl: [],
            operationRadio: "合格",
            opDesc: '',
            checkId: '',
            imgFlag: false,
            preRotationX: 0,
            postRotationX: 0,
            leftRotationZ: 0,
            rightRotationZ: 0,
            ruleValue: "",
            colors: [
                "#FA5C90",
                "#46D9FF",
                "#4990FE",
                "#856DFE",
                "#FFC880",
                "#29b6f6",
                "#8bc34a",
                "#fbc02d",
                "#b3e5fc",
                "#ef5350",
                "#4dd0e1",
                "#304ffe",
                "#ff4081",
                "#82b1ff",
                "#6a1b9a",
                "#f57f17",
                "#b71c1c",
                "#a5d6a7",
                "#ffab91",
                "#880e4f",
                "#f8bbd0"
            ],
            fenceObjList: [],
        }
    },
    watch: {
        reportImgUrl(val, oldVal) {
            if (val.length == 10) {
                this.imgFlag = true
            } else {
                this.imgFlag = false

            }
        },
    },
    methods: {
        // 获取质量问题上报详情
        getReportDetails(id, type) {
            this.checkId = id;
            let userId = localStorage.getItem("userId");
            let parmas = {
                checkId: id
            }
            if (type == 8) {
                problemReportDetails(parmas).then((res) => {
                    if (res.code == 200) {
                        let data = res.data;
                        let operationState = data.state;
                        let logArr = data.logList;
                        let userArr = data.userList;
                        let operatorName = "";
                        let reviewName = "";
                        let checkName = "";
                        let sendName = "";
                        let userList = [];
                        let logList = [];
                        let operationFlag = "";
                        let active = "";
                        userArr.forEach((v, i) => {
                            if (operationState != 100) {
                                if (v.type == 1) {
                                    v.name = '上报';
                                } else if (v.type == 2) {
                                    if (operationState == 20) {
                                        v.name = '整改合格';
                                    } else {
                                        v.name = '待整改';
                                    }
                                    operatorName = v.userName
                                } else if (v.type == 3) {
                                    if (operationState == 30) {
                                        v.name = '复查合格';
                                    } else {
                                        v.name = '待复查';
                                    }
                                    reviewName = v.userName
                                } else if (v.type == 4) {
                                    if (operationState == 40) {
                                        v.name = '核验合格';
                                    } else {
                                        v.name = '待核验';
                                    }
                                    checkName = v.userName
                                } else if (v.type == 5) {
                                    if (userArr.length - 1 == i) {
                                        sendName += v.userName
                                    } else {
                                        sendName += v.userName + ','
                                    }
                                }
                            } else {
                                if (v.type == 1) {
                                    v.name = '上报';
                                } else if (v.type == 2) {
                                    v.name = '整改合格';
                                    operatorName = v.userName
                                } else if (v.type == 3) {
                                    v.name = '复查合格';
                                    reviewName = v.userName
                                } else if (v.type == 4) {
                                    v.name = '核验合格';
                                    checkName = v.userName
                                } else if (v.type == 5) {
                                    if (userArr.length - 1 == i) {
                                        sendName += v.userName
                                    } else {
                                        sendName += v.userName + ','
                                    }
                                }
                            }

                            if (v.type < 5) {
                                userList.push(v)
                            }
                        })
                        logArr.forEach((v, i) => {
                            userArr.forEach((val, index) => {
                                if (v.opType == val.type) {
                                    val.time = v.opTime
                                }
                            })
                            if (v.opType !== 1) {
                                logList.push(v)
                            }
                        })
                        for (let i = 0; i < userArr.length; i++) {
                            const e = userArr[i];
                            if (e.type == 2) {
                                if (operationState == 10 || operationState == 11 || operationState == 12) {
                                    if (userId == e.userId) {
                                        operationFlag = 1;
                                    }
                                    userArr[1].time = ""
                                    userArr[2].time = ""
                                    userArr[3].time = ""
                                }
                            } else if (e.type == 3) {
                                if (operationState == 20) {
                                    if (userId == e.userId) {
                                        operationFlag = 2;
                                    }
                                    userArr[2].time = ""
                                    userArr[3].time = ""
                                }
                            } else if (e.type == 4) {
                                if (operationState == 30) {
                                    if (userId == e.userId) {
                                        operationFlag = 3;
                                    }
                                    userArr[3].time = ""
                                }
                            }
                        }
                        if (operationState == 10 || operationState == 11 || operationState == 12) {
                            active = 2;
                        }
                        if (operationState == 20) {
                            active = 3;
                        }
                        if (operationState == 30) {
                            active = 4;
                        }
                        if (operationState == 100) {
                            active = 4;
                        }
                        this.problemReport = data
                        this.problemReport.operatorName = operatorName;
                        this.problemReport.reviewName = reviewName;
                        this.problemReport.checkName = checkName;
                        this.problemReport.sendName = sendName;
                        this.problemReport.logList = logList;
                        this.problemReport.userList = userList;
                        this.problemReport.operationFlag = operationFlag;
                        this.problemReport.active = active;
                        this.handleReportModal = true;
                    } else {
                        this.$Message.warning(res.msg);
                    }

                }).catch((err) => {
                    console.log(err)
                });
            } else {
                safetyProblemReportDetails(parmas).then((res) => {
                    if (res.code == 200) {
                        let data = res.data;
                        let operationState = data.state;
                        let logArr = data.logList;
                        let userArr = data.userList;
                        let operatorName = "";
                        let reviewName = "";
                        let checkName = "";
                        let sendName = "";
                        let userList = [];
                        let logList = [];
                        let operationFlag = "";
                        let active = "";
                        userArr.forEach((v, i) => {
                            if (operationState != 100) {
                                if (v.type == 1) {
                                    v.name = '上报';
                                } else if (v.type == 2) {
                                    if (operationState == 20) {
                                        v.name = '整改合格';
                                    } else {
                                        v.name = '待整改';
                                    }
                                    operatorName = v.userName
                                } else if (v.type == 3) {
                                    if (operationState == 30) {
                                        v.name = '复查合格';
                                    } else {
                                        v.name = '待复查';
                                    }
                                    reviewName = v.userName
                                } else if (v.type == 4) {
                                    if (operationState == 40) {
                                        v.name = '核验合格';
                                    } else {
                                        v.name = '待核验';
                                    }
                                    checkName = v.userName
                                } else if (v.type == 5) {
                                    if (userArr.length - 1 == i) {
                                        sendName += v.userName
                                    } else {
                                        sendName += v.userName + ','
                                    }
                                }
                            } else {
                                if (v.type == 1) {
                                    v.name = '上报';
                                } else if (v.type == 2) {
                                    v.name = '整改合格';
                                    operatorName = v.userName
                                } else if (v.type == 3) {
                                    v.name = '复查合格';
                                    reviewName = v.userName
                                } else if (v.type == 4) {
                                    v.name = '核验合格';
                                    checkName = v.userName
                                } else if (v.type == 5) {
                                    if (userArr.length == i) {
                                        sendName += v.userName
                                    } else {
                                        sendName += v.userName + ','
                                    }
                                }
                            }

                            if (v.type < 5) {
                                userList.push(v)
                            }
                        })
                        logArr.forEach((v, i) => {
                            userArr.forEach((val, index) => {
                                if (v.opType == val.type) {
                                    val.time = v.opTime
                                }
                            })
                            if (v.opType !== 1) {
                                logList.push(v)
                            }
                        })
                        for (let i = 0; i < userArr.length; i++) {
                            const e = userArr[i];
                            if (e.type == 2) {
                                if (operationState == 10 || operationState == 11 || operationState == 12) {
                                    if (userId == e.userId) {
                                        operationFlag = 1;
                                    }
                                    userArr[1].time = ""
                                    userArr[2].time = ""
                                    userArr[3].time = ""
                                }
                            } else if (e.type == 3) {
                                if (operationState == 20) {
                                    if (userId == e.userId) {
                                        operationFlag = 2;
                                    }
                                    userArr[2].time = ""
                                    userArr[3].time = ""
                                }
                            } else if (e.type == 4) {
                                if (operationState == 30) {
                                    if (userId == e.userId) {
                                        operationFlag = 3;
                                    }
                                    userArr[3].time = ""
                                }
                            }
                        }
                        if (operationState == 10 || operationState == 11 || operationState == 12) {
                            active = 2;
                        }
                        if (operationState == 20) {
                            active = 3;
                        }
                        if (operationState == 30) {
                            active = 4;
                        }
                        if (operationState == 100) {
                            active = 4;
                        }
                        this.problemReport = data
                        this.problemReport.operatorName = operatorName;
                        this.problemReport.reviewName = reviewName;
                        this.problemReport.checkName = checkName;
                        this.problemReport.sendName = sendName;
                        this.problemReport.logList = logList;
                        this.problemReport.userList = userList;
                        this.problemReport.operationFlag = operationFlag;
                        this.problemReport.active = active;
                        this.handleSafetyReportModal = true;
                    } else {
                        this.$Message.warning(res.msg);
                    }

                }).catch((err) => {
                    console.log(err)
                });
            }

        },
        //劳务模块消息详情
        getEmpDetails(id) {
            let parmas = {
                warnId: id
            };
            getEmpRecordDetail(parmas)
                .then(res => {
                    if (res.code == 200) {
                        if (res.data.handleState == 1) {
                            this.isAdd = false;
                            this.handleRemark = res.data.handleRemark;
                            this.handleResult = res.data.handleResult;
                        } else if (res.data.handleState == 0) {
                            this.isAdd = true;
                            this.handleRemark = "";
                            this.handleResult = "";
                        }
                        this.handleEmpModal = true;
                        this.handleTime = res.data.handleTime;
                        this.handleUserName = res.data.handleUserName;
                        this.empName = res.data.empName;
                        this.workTypeName = res.data.workTypeName;
                        this.ruleType = res.data.ruleType;
                        this.type = res.data.type;
                        this.pointList = res.data.pointList;
                        this.centerPoint = res.data.centerPoint;
                        this.radius = res.data.radius;
                        this.timeList = res.data.timeList;
                        this.triggerTime = res.data.triggerTime;
                        var _that = this;
                        // 经纬度转坐标
                        AMap.service("AMap.Geocoder", function () {
                            //回调函数
                            //实例化Geocoder
                            var geocoder = new AMap.Geocoder({
                                city: "", //城市，默认:“全国”
                                radius: 1000,
                                extensions: "all"
                            });
                            var lnglatXY = [res.data.lng, res.data.lat]; //地图上所标点的坐标
                            // var lnglatXY = [114.29484, 30.592335]; //地图上所标点的坐标
                            geocoder.getAddress(lnglatXY, function (status, result) {
                                if (status === "complete" && result.info === "OK") {
                                    //获得了有效的地址信息:
                                    //即，result.regeocode.formattedAddress
                                    var city =
                                        result.regeocode.formattedAddress;
                                } else {
                                    var city = "暂无位置信息";
                                    //获取地址失败
                                }
                                _that.ads = city;
                            });
                        });
                    } else {
                        this.$Message.warning(res.msg);
                    }
                })
                .catch(error => {
                    console.log(error);
                });
        },
        getEmpHandle(obj, type) {
            getEmpRecordHandle(obj)
                .then(res => {
                    if (res.code == 200) {
                        this.$Message.success("操作成功");
                        this.pageNum = 1;
                        this.current = 1;
                        if (type) {
                            this.getAllMsg();
                        }
                        this.handleEmpModal = false;
                        this.handleSModal = false;
                    } else {
                        this.$Message.warning(res.msg);
                    }
                })
                .catch(error => {
                    console.log(error);
                });
        },
        //环境模块消息详情
        getEnvDetails(id) {
            let parmas = {
                id: id
            };
            getEnvRecordDetails(parmas)
                .then(res => {
                    if (res.code == 200) {
                        if (res.data.handleState == 1) {
                            this.handleRemark = res.data.handleRemark;
                            this.handleResult = res.data.handleResult;
                            this.isAdd = false;
                        } else if (res.data.handleState == 0) {
                            this.handleRemark = "";
                            this.handleResult = "";
                            this.isAdd = true;
                        }
                        this.handleEnvModal = true;
                        this.deviceType = res.data.deviceType;
                        this.envName = res.data.name;
                        this.ruleType = res.data.ruleType;
                        this.ruleMinValue = res.data.ruleMinValue;
                        this.ruleType = res.data.ruleType;
                        this.ruleMinValue = res.data.ruleMinValue;
                        this.triggerTime = res.data.triggerTime;
                        this.triggerValue = res.data.triggerValue || 0;
                        this.handleTime = res.data.handleTime;
                        this.handleUserName = res.data.handleUserName;
                    } else {
                        this.$Message.warning(res.msg);
                    }
                })
                .catch(error => {
                    console.log(error);
                });
        },
        getEnvHandle(obj, type) {
            getEnvRecordHandle(obj)
                .then(res => {
                    if (res.code == 200) {
                        this.$Message.success("操作成功");
                        this.msgPageNum = 1;
                        this.msgCurrent = 1;
                        if (type) {
                            this.getAllMsg();
                        }
                        this.handleEnvModal = false;
                        this.handleSModal = false;
                    } else {
                        this.$Message.warning(res.msg);
                    }
                })
                .catch(error => {
                    console.log(error);
                });
        },
        //考勤设备消息详情
        getEquipDetails(id, flag) {
            let parmas = {
                warnId: id
            };
            getEquipRecordDetail(parmas)
                .then(res => {
                    if (res.code == 200) {
                        if (res.data.handleState == 1) {
                            this.handleRemark = res.data.handleRemark;
                            this.handleResult = res.data.handleResult;
                            this.isAdd = false;
                        } else if (res.data.handleState == 0) {
                            this.handleRemark = "";
                            this.handleResult = "";
                            this.isAdd = true;
                        }
                        this.handleEquipModal = true;
                        this.handleTime = res.data.handleTime;
                        this.handleUserName = res.data.handleUserName;
                        this.machTypeName = res.data.machTypeName;
                        this.machBrandName = res.data.machBrandName;
                        this.machModelName = res.data.machModelName;
                        this.machCode = res.data.code;
                        this.operatorList = res.data.operatorList;
                        this.ruleType = res.data.ruleType;
                        this.ruleMaxValue = res.data.ruleMaxValue;
                        this.fenceObjList = res.data.fenceList;
                        if (this.fenceObjList.length == 1 && this.fenceObjList[0].fenceId == undefined) {
                            this.type = this.fenceObjList[0].type;
                        }
                        this.timeList = res.data.timeList;
                        this.triggerTime = res.data.triggerTime;
                        this.triggerValue = res.data.triggerValue;
                        var _that = this;
                        //电子围栏报警时报警详情
                        if (this.ruleType == 101) {
                            let lng, lat, polygon, circle;
                            let maplng, maplat
                            if (this.fenceObjList[0].type == 1) {
                                //计算多边形中心点的坐标;
                                var polygonPointList = this.fenceObjList[0].polygonPointList;
                                var a = [];
                                var b = [];
                                for (let i in polygonPointList) {
                                    a.push(polygonPointList[i].lat);
                                    b.push(polygonPointList[i].lng);
                                    //多边形的坐标点
                                    let x = [polygonPointList[i].lng, polygonPointList[i].lat];
                                }
                                let latSum = 0;
                                for (let i in a) {
                                    latSum += a[i];
                                }
                                maplat = latSum / a.length;
                                let lngSum = 0;
                                for (let i in b) {
                                    lngSum += b[i];
                                }
                                maplng = lngSum / b.length;
                            } else if (this.fenceObjList[0].type == 2) {
                                maplat = this.fenceObjList[0].centerPoint.lat;
                                maplng = this.fenceObjList[0].centerPoint.lng;
                            }
                            if (flag) {
                                var machmap = new AMap.Map("fenceMap30", {
                                    resizeEnable: true, //是否监控地图容器尺寸变化
                                    zoom: 14, //初始化地图层级
                                    center: [maplng, maplat], //初始化地图中心点
                                    layers: [
                                        // 卫星
                                        new AMap.TileLayer.Satellite(),
                                        // 路网
                                        new AMap.TileLayer.RoadNet()
                                    ]
                                });
                            } else {
                                var machmap = new AMap.Map("fenceMap3", {
                                    resizeEnable: true, //是否监控地图容器尺寸变化
                                    zoom: 14, //初始化地图层级
                                    center: [maplng, maplat], //初始化地图中心点
                                    layers: [
                                        // 卫星
                                        new AMap.TileLayer.Satellite(),
                                        // 路网
                                        new AMap.TileLayer.RoadNet()
                                    ]
                                });
                            }
                            this.fenceObjList.forEach((v, i) => {
                                if (v.type == 1) {
                                    //计算多边形中心点的坐标;
                                    let polygonPointList = v.polygonPointList;
                                    let path = [];
                                    for (let j in polygonPointList) {
                                        //多边形的坐标点
                                        let x = [polygonPointList[j].lng, polygonPointList[j].lat];
                                        path.push(x);
                                    }
                                    polygon = new AMap.Polygon({
                                        path: path,
                                        strokeColor: this.colors[i],
                                        strokeWeight: 6,
                                        strokeOpacity: 0.5,
                                        fillOpacity: 0.8,
                                        fillColor: this.colors[i],
                                        zIndex: 50
                                    });
                                    machmap.add(polygon);
                                    // 缩放地图到合适的视野级别
                                    machmap.setFitView([polygon])
                                } else if (v.type == 2) {
                                    lat = v.centerPoint.lat;
                                    lng = v.centerPoint.lng;
                                    let radius = v.radius;
                                    circle = new AMap.Circle({
                                        center: [lng, lat],
                                        radius: radius, //半径
                                        borderWeight: 3,
                                        strokeColor: this.colors[i],
                                        strokeWeight: 6,
                                        strokeOpacity: 0.5,
                                        fillOpacity: 0.8,
                                        strokeStyle: "dashed",
                                        strokeDasharray: [10, 10],
                                        // 线样式还支持 'dashed'
                                        fillColor: this.colors[i],
                                        zIndex: 50
                                    });
                                    circle.setMap(machmap);
                                    // 缩放地图到合适的视野级别
                                    machmap.setFitView([circle]);
                                }
                            });
                            //标记设备的区域
                            var marker;
                            marker = new AMap.Marker({
                                map: machmap,
                                icon: new AMap.Icon({
                                    image: res.data.icon,
                                    size: new AMap.Size(128, 128), //图标大小
                                    imageSize: new AMap.Size(64, 64)
                                }),
                                position: [res.data.lng, res.data.lat],
                                offset: new AMap.Pixel(-13, -30)
                            });
                            var mouseTool = new AMap.MouseTool(machmap);
                            // 构造官方卫星、路网图层
                            var satelliteLayer = new AMap.TileLayer.Satellite();
                            var roadNetLayer = new AMap.TileLayer.RoadNet();
                            //添加图层
                            machmap.add([satelliteLayer, roadNetLayer]);
                        }
                        // 经纬度转坐标
                        AMap.service("AMap.Geocoder", function () {
                            //回调函数
                            //实例化Geocoder
                            var geocoder = new AMap.Geocoder({
                                city: "", //城市，默认:“全国”
                                radius: 1000,
                                extensions: "all"
                            });
                            var lnglatXY = [res.data.lng, res.data.lat]; //地图上所标点的坐标
                            // var lnglatXY = [114.29484, 30.592335]; //地图上所标点的坐标
                            geocoder.getAddress(lnglatXY, function (status, result) {
                                if (status === "complete" && result.info === "OK") {
                                    //获得了有效的地址信息:
                                    //即，result.regeocode.formattedAddress
                                    var city =
                                        result.regeocode.formattedAddress;
                                } else {
                                    var city = "暂无位置信息";
                                    //获取地址失败
                                }
                                _that.ads = city;
                            });
                        });
                    } else {
                        this.$Message.warning(res.msg);
                    }
                })
                .catch(error => {
                    console.log(error);
                });
        },
        getEquipHandle(obj, type) {
            getEquipRecordHandle(obj)
                .then(res => {
                    if (res.code == 200) {
                        this.$Message.success("操作成功");
                        if (type) {
                            this.getAllMsg();
                        }
                        this.handleEquipModal = false;
                        this.handleSModal = false;
                    } else {
                        this.$Message.warning(res.msg);
                    }
                })
                .catch(error => {
                    console.log(error);
                });
        },
        //智能监控模块消息详情
        getFimDetails(id) {
            let parmas = {
                resultId: id
            };
            getFimResultDetail(parmas)
                .then(res => {
                    if (res.code == 200) {
                        if (res.data.handleStatus == 1) {
                            this.handleRemark = res.data.handleRemark;
                            this.handleResult = res.data.handleResult;
                            this.isAdd = false;
                        } else if (res.data.handleStatus == 0) {
                            this.handleRemark = "";
                            this.handleResult = "";
                            this.isAdd = true;
                        }
                        this.handleFimModal = true;
                        this.deviceName = res.data.deviceName;
                        this.personNameList = res.data.personNameList;
                        this.triggerTime = res.data.time;
                        this.algCheckType = res.data.algCheckType;
                        this.algCheckTypeName = res.data.algCheckTypeName;
                        this.handleTime = res.data.handleTime;
                        this.handleUserName = res.data.handleUser;
                        this.imgList = res.data.resultImgUrlList;
                    } else {
                        this.$Message.warning(res.msg);
                    }
                })
                .catch(error => {
                    console.log(error);
                });
        },
        getFimHandle(obj, type) {
            getFimResultHandle(obj)
                .then(res => {
                    if (res.code == 200) {
                        this.$Message.success("操作成功");
                        this.msgPageNum = 1;
                        this.msgCurrent = 1;
                        if (type) {
                            this.getAllMsg();
                        }
                        this.handleFimModal = false;
                        this.handleSModal = false;
                    } else {
                        this.$Message.warning(res.msg);
                    }
                })
                .catch(error => {
                    console.log(error);
                });
        },
        //特种设备模块消息详情
        getFseDetails(id) {
            let parmas = {
                id: id
            };
            getFseRecordDetails(parmas)
                .then(res => {
                    if (res.code == 200) {
                        if (res.data.handleState == 1) {
                            this.handleRemark = res.data.handleRemark;
                            this.handleResult = res.data.handleResult;
                            this.isAdd = false;
                        } else if (res.data.handleState == 0) {
                            this.handleRemark = "";
                            this.handleResult = "";
                            this.isAdd = true;
                        }
                        this.handleFseModal = true;
                        this.type = res.data.type;
                        this.modelName = res.data.modelName;
                        this.code = res.data.code;
                        this.operatorList = res.data.operatorList;
                        this.ruleType = res.data.ruleType;
                        this.ruleMaxValue = res.data.ruleMaxValue;
                        this.ruleMinValue = res.data.ruleMinValue;
                        this.triggerTime = res.data.triggerTime;
                        this.triggerValue = res.data.triggerValue;
                        this.handleTime = res.data.handleTime;
                        this.handleUserName = res.data.handleUserName;
                    } else {
                        this.$Message.warning(res.msg);
                    }
                })
                .catch(error => {
                    console.log(error);
                });
        },
        getFseHandle(obj, type) {
            getFseRecordHandle(obj)
                .then(res => {
                    if (res.code == 200) {
                        this.$Message.success("操作成功");
                        this.msgPageNum = 1;
                        this.msgCurrent = 1;
                        if (type) {
                            this.getAllMsg();
                        }
                        this.handleFseModal = false;
                        this.handleSModal = false;
                    } else {
                        this.$Message.warning(res.msg);
                    }
                })
                .catch(error => {
                    console.log(error);
                });
        },
        //设备模块消息详情
        getMachDetails(id, flag) {
            let parmas = {
                id: id
            };
            getMachRecordDetail_V1(parmas)
                .then(res => {
                    if (res.code == 200) {
                        if (res.data.handleState == 1) {
                            this.isAdd = false;
                            this.handleRemark = res.data.handleRemark;
                            this.handleResult = res.data.handleResult;
                        } else if (res.data.handleState == 0) {
                            this.isAdd = true;
                            this.handleRemark = "";
                            this.handleResult = "";
                        }
                        this.handleMachModal = true;
                        this.handleTime = res.data.handleTime;
                        this.handleUserName = res.data.handleUserName;
                        this.machTypeName = res.data.machTypeName;
                        // this.machBrandName = res.data.machBrandName;
                        // this.machModelName = res.data.machModelName;
                        this.machCode = res.data.machCode;
                        this.operatorList = res.data.operatorList;
                        this.ruleType = res.data.ruleType;
                        this.ruleValue = res.data.ruleValue;
                        this.type = res.data.type;
                        this.pointList = res.data.pointList;
                        this.centerPoint = res.data.centerPoint;
                        this.radius = res.data.radius;
                        this.timeList = res.data.timeList;
                        this.triggerTime = res.data.triggerTime;
                        this.triggerValue = res.data.triggerValue || 0;
                        if (this.ruleType == 110) {
                            this.preRotationX = res.data.machRotationRuleDTO.preRotationX || 0;
                            this.postRotationX = res.data.machRotationRuleDTO.postRotationX || 0;
                            this.leftRotationZ = res.data.machRotationRuleDTO.leftRotationZ || 0;
                            this.rightRotationZ = res.data.machRotationRuleDTO.rightRotationZ || 0;
                        }
                        var _that = this;
                        //电子围栏报警时报警详情
                        if (this.ruleType == 101) {
                            if (_that.type == 1) {
                                var polygonPointList = _that.pointList;
                                var a = [];
                                var b = [];
                                var path = [];
                                for (let i in polygonPointList) {
                                    a.push(polygonPointList[i].lat);
                                    b.push(polygonPointList[i].lng);
                                    //多边形的坐标点
                                    let x = [
                                        polygonPointList[i].lng,
                                        polygonPointList[i].lat
                                    ];
                                    path.push(x);
                                }
                                let latSum = 0;
                                for (let i in a) {
                                    latSum += a[i];
                                }
                                var lat = latSum / a.length;
                                let lngSum = 0;
                                for (let i in b) {
                                    lngSum += b[i];
                                }
                                var lng = lngSum / b.length;
                                var machpolygon = new AMap.Polygon({
                                    path: path,
                                    strokeColor: "#ff00ff",
                                    strokeWeight: 6,
                                    strokeOpacity: 0.2,
                                    fillOpacity: 0.4,
                                    fillColor: "#ff00ff",
                                    zIndex: 50
                                });
                                var machmap;
                                if (flag) {
                                    machmap = new AMap.Map("fenceMap20", {
                                        zoom: 14,
                                        center: [lng, lat]
                                    });
                                } else {
                                    machmap = new AMap.Map("fenceMap2", {
                                        zoom: 14,
                                        center: [lng, lat]
                                    });
                                }
                            } else if (_that.type == 2) {
                                var lat = _that.centerPoint.lat;
                                var lng = _that.centerPoint.lng;
                                var radius = _that.radius;
                                var machcircle = new AMap.Circle({
                                    center: [lng, lat],
                                    radius: radius, //半径
                                    borderWeight: 3,
                                    strokeColor: "#ff00ff",
                                    strokeOpacity: 1,
                                    strokeWeight: 6,
                                    fillOpacity: 0.4,
                                    strokeStyle: "dashed",
                                    strokeDasharray: [10, 10],
                                    // 线样式还支持 'dashed'
                                    fillColor: "#ff00ff",
                                    zIndex: 50
                                });
                                var machmap
                                if (flag) {
                                    machmap = new AMap.Map("fenceMap20", {
                                        zoom: 14,
                                        center: [lng, lat]
                                    });
                                } else {
                                    machmap = new AMap.Map("fenceMap2", {
                                        zoom: 14,
                                        center: [lng, lat]
                                    });
                                }
                            }
                            //标记设备的区域
                            var marker;
                            marker = new AMap.Marker({
                                map: machmap,
                                icon: new AMap.Icon({
                                    image: res.data.machTypeIcon,
                                    size: new AMap.Size(128, 128), //图标大小
                                    imageSize: new AMap.Size(64, 64)
                                }),
                                // icon:require("./../../assets/images/wjj_0.png"),
                                position: [res.data.lng, res.data.lat],
                                offset: new AMap.Pixel(-13, -30)
                            });
                            var mouseTool = new AMap.MouseTool(machmap);
                            // 构造官方卫星、路网图层
                            var satelliteLayer = new AMap.TileLayer.Satellite();
                            var roadNetLayer = new AMap.TileLayer.RoadNet();
                            //添加图层
                            machmap.add([satelliteLayer, roadNetLayer]);
                            if (_that.type == 1) {
                                machmap.add(machpolygon);
                                // 缩放地图到合适的视野级别
                                machmap.setFitView([machpolygon]);
                            } else if (_that.type == 2) {
                                // circle.setMap(map);
                                machmap.add(machcircle);
                                // 缩放地图到合适的视野级别
                                machmap.setFitView([machcircle]);
                            }
                        }
                        // 经纬度转坐标
                        AMap.service("AMap.Geocoder", function () {
                            //回调函数
                            //实例化Geocoder
                            var geocoder = new AMap.Geocoder({
                                city: "", //城市，默认:“全国”
                                radius: 1000,
                                extensions: "all"
                            });
                            var lnglatXY = [res.data.lng, res.data.lat]; //地图上所标点的坐标
                            // var lnglatXY = [114.29484, 30.592335]; //地图上所标点的坐标
                            geocoder.getAddress(lnglatXY, function (status, result) {
                                if (status === "complete" && result.info === "OK") {
                                    //获得了有效的地址信息:
                                    //即，result.regeocode.formattedAddress
                                    var city = result.regeocode.formattedAddress;
                                } else {
                                    var city = "暂无位置信息";
                                    //获取地址失败
                                }
                                _that.ads = city;
                            });
                        });
                    } else {
                        this.$Message.warning(res.msg);
                    }
                })
                .catch(error => {
                    console.log(error);
                });
        },
        getMachHandle(obj, type) {
            getMachRecordHandle_V1(obj)
                .then(res => {
                    if (res.code == 200) {
                        this.$Message.success("操作成功");
                        this.msgPageNum = 1;
                        this.msgCurrent = 1;
                        if (type) {
                            this.getAllMsg();
                        }
                        this.handleMachModal = false;
                        this.handleSModal = false;
                    } else {
                        this.$Message.warning(res.msg);
                    }
                })
                .catch(error => {
                    console.log(error);
                });
        },
        beforeIMgUpload(file) {
            const isLt2M = file.size / 1024 / 1024 < 2;
            if (!isLt2M) {
                this.$Message.error("上传图片大小不能超过 2MB!");
            }
            return isLt2M;
        },
        logImgSuccess(res, file) {
            this.reportImgUrl.push(res.data);
        },
        exceedImg(files, fileList) {
            if (this.reportImgUrl.length == 10) {
                this.$Message.warning('上传图片最多10张');
                return;
            }
            if (this.submitData.reportImgUrl.length == 10) {
                this.$Message.warning('上传图片最多10张');
                return;
            }
        },
        handleRemove(file, fileList) {
            this.reportImgUrl = []
            fileList.forEach(v => {
                this.reportImgUrl.push(v.response.data)
            })
        },
        problemLogBtn(type) {
            let operationRadio = this.operationRadio;
            if (operationRadio == '合格') {
                operationRadio = 1;
            } else {
                operationRadio = 2;
            }
            if (this.opDesc == "") {
                if (this.problemReport.active == 2) {
                    this.$Modal.warning({
                        title: "您有必填字段",
                        content: "请填写整改说明"
                    });
                    return;
                } else if (this.problemReport.active == 3) {
                    this.$Modal.warning({
                        title: "您有必填字段",
                        content: "请填写复查说明"
                    });
                    return;
                } else if (this.problemReport.active == 4) {
                    this.$Modal.warning({
                        title: "您有必填字段",
                        content: "请填写核验说明"
                    });
                    return;
                }
            }
            let parmas = {
                checkId: this.checkId,
                opType: this.problemReport.active,
                opDesc: this.opDesc,
                opResult: operationRadio,
                imgUrls: this.reportImgUrl,
            }
            if (type == 8) {
                problemReportLog(parmas).then((res) => {
                    if (res.code == 200) {
                        this.checkId = '';
                        this.problemReport.active = '';
                        this.opResult = '';
                        this.opDesc = '';
                        this.reportImgUrl = [];
                        this.operationRadio = '合格'
                        this.handleReportModal = false;
                        this.$Message.success('操作成功');
                        this.$refs.uploadImg.clearFiles();
                        this.getAllMsg();
                    } else {
                        this.$Message.warning(res.msg);
                    }
                }).catch((err) => {
                    console.log(err)
                });
            } else {
                safetyProblemReportLog(parmas).then((res) => {
                    if (res.code == 200) {
                        this.checkId = '';
                        this.problemReport.active = '';
                        this.opResult = '';
                        this.opDesc = '';
                        this.reportImgUrl = [];
                        this.operationRadio = '合格'
                        this.handleSafetyReportModal = false;
                        this.$Message.success('操作成功');
                        this.$refs.uploadImg.clearFiles();
                        this.getAllMsg();
                    } else {
                        this.$Message.warning(res.msg);
                    }
                }).catch((err) => {
                    console.log(err)
                });
            }

        },

    },
    mounted() {
        //   this.getLink();
    },
}
